import random

user = [["账号", "姓名", "密码", "地址", "存款余额", "中国工商银行"]]
address = [["国家", "省份", "街道", "门牌号"]]
yinghang = {}


def interface():
    print("***********************")
    print("*****中国工商银行******")
    print("*****账户管理系统******")
    print("*********v1.0***********")
    print("***********************")
    print()
    print("*1.开户                           *")
    print("*2.存钱                           *")
    print("*3.取钱                           *")
    print("*4.转账                           *")
    print("*5.查询                           *")
    print("*6.bye!                           *")
    print("***********************")


# 开户
def add():
    user_list = []
    address_list = []
    for i in user:
        while True:
            number = random.randint(10000000, 99999999)
            if number in i:
                return 2
            else:
                user_list.append(str(number))
                user_list.append(input("姓名"))
                user_list.append(int(input("密码")))

                address_list.append(input("国家"))
                address_list.append(input("省份"))
                address_list.append(input("街道"))
                address_list.append(input("门牌号"))
                user_list.append(address_list)

                user_list.append(int(input("存款余额")))
                user_list.append("中国工商银行")
                user.append(user_list)

                k = str(number)
                v = user_list
                yinghang.update({k: v})
                print(yinghang)
                return 1
            if len(yinghang) > 100:
                return 3


# 存钱
def save():
    number = input("请输入账号：")
    money = int(input("请输入存款余额："))
    for i in user:
        if number in i:
            i[4] += money
            return True
    print("账号不存在")
    return False


# 取钱
def take():
    print(user)
    number = input("请输入账号：")
    for i in range(1, len(user)):
        if number == user[i][0]:
            password = int(input("请输入密码："))
            if password == user[i][2]:
                money = int(input("请输入取钱金额："))
                if user[i][4] > money:
                    user[i][4] -= money
                else:
                    return 3

            elif i == len(user) - 1:
                if password != user[i][2]:
                    return 2
        elif i == len(user) - 1:
            if number != user[i][0]:
                return 1


# 转账
def acc():
    print(user)
    number1 = input("请输入转入账号：")
    number2 = input("请输入转出账号：")
    for i in range(1, len(user)):
        if number1 == user[i][0]:
            for j in range(1, len(user)):
                if number2 == user[j][0]:
                    password = int(input("请输入转出账号的密码："))
                    if password == user[j][2]:
                        money = int(input("请输入转账金额："))
                        if user[j][4] >= money:
                            user[j][4] -= money
                            user[i][4] += money
                            return 4
                        else:
                            return 3
                    elif password!=user[j][2]:
                        return 2
                elif j == len(user) - 1:
                    if number2 != user[j][0]:
                        return 1
        elif i == len(user) - 1:
            if number1 != user[i][0]:
                return 1


# 查询
def search():
    print(user)
    number = input("请输入账号：")
    for i in range(1, len(user)):
        if number == user[i][0]:
            password = int(input("请输入密码："))
            if password == user[i][2]:
                print(f"账号：{yinghang[number][0]}，姓名：{yinghang[number][1]}，密码：{yinghang[number][2]}，地址：{yinghang[number][3]}，存款余额：{yinghang[number][4]}，开户行：{yinghang[number][5]}")
                return
            else:
                print("密码错误")
                return
        elif i == len(user) - 1:
            if number != user[i][0]:
                print("账号错误")
                return


def result():
    interface()
    while True:
        n = int(input("请选择："))
        # 开户
        if n == 1:
            x = add()
            if x == 1:
                print("成功")
            elif x == 2:
                print("用户已存在")
            elif x == 3:
                print("用户库已满")
        # 存钱
        elif n == 2:
            save()
        # 取钱
        elif n == 3:
            x = take()
            if x == 1:
                print("账号不存在")
            elif x == 2:
                print("密码错误")
            elif x == 3:
                print("余额不足")
        # 转账
        elif n == 4:
            x = acc()
            if x == 1:
                print("账号不存在")
            elif x == 2:
                print("密码错误")
            elif x == 3:
                print("金额不足")
            elif x==4:
                print("转账成功")
        # 查询
        elif n == 5:
            search()
        # 退出
        elif n == 6:
            break


result()
